package com.scujj.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class ResultUtil{
    public static <T> T singleTrans(Object data, Class<T> clazz){
        JSONObject jsonObject = new JSONObject();
        jsonObject.putAll((Map)data);
        return jsonObject.toJavaObject(clazz);
    }

    public static <T> List<T> listTrans(Object data, Class<T> clazz){
        JSONArray jsonArray=new JSONArray();
        jsonArray.addAll((List)data);
        List<T> resultList=new LinkedList<>();
        jsonArray.forEach(o -> {
            resultList.add(singleTrans(o,clazz));
        });
        return resultList;
    }
}
